Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Status events #70

Merged
merged 3 commits into from
Jul 12, 2024
Merged

Status events #70

merged 3 commits into from
Jul 12, 2024

Conversation

eriktaubeneck
Copy link
Member

@eriktaubeneck eriktaubeneck commented Jul 10, 2024

This updates the sidecar to store the entire status history of a query, instead of just the current status. It also includes a timestamp. With that timestamp, we're then able to simply update the run time based on when the current status started, and in the case where it's complete/finished/crashed, it shows the difference between start and end time.

Summary by CodeRabbit

  • New Features

    • Introduced start and end time tracking for remote servers to provide more detailed runtime data.
  • Enhancements

    • Improved the runtime calculation by displaying dynamic runtime based on start and end times.
  • Bug Fixes

    • Updated socket handling to correctly manage start and end times, ensuring accurate status updates.
  • Backend Improvements

    • Added status change history tracking and enhanced status event handling for more accurate server status reporting.

Copy link

vercel bot commented Jul 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
draft ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 12, 2024 10:44pm

Copy link
Contributor

coderabbitai bot commented Jul 10, 2024

Walkthrough

This update refactors the handling of server runtimes by introducing start and end times, replacing the old runtime logic. It modifies various components and functions to manage and display start and end times dynamically. Changes span multiple files, including TypeScript and Python, involving updates to types, state handling, and response formats.

Changes

File(s) Change Summary
server/app/query/servers.tsx Renamed RunTimeByRemoteServer to StartTimeByRemoteServer, added EndTimeByRemoteServer, updated functions to handle both.
server/app/query/view/[id]/components.tsx Renamed runTime prop to startTime and endTime, added logic for dynamic runtime calculations.
server/app/query/view/[id]/page.tsx Updated state variables and socket handling for new start and end time logic.
sidecar/app/query/base.py Introduced StatusChangeEvent named tuple, removed _status field, added methods for handling status history.
sidecar/app/routes/websockets.py Added start_time to JSON response, replaced run_time with query.status_event_json in status updates.

Poem

On servers' start and end we dwell,
In code where distant data swell,
With queries, states, we redefine,
The times we track, like stars align.
A journey marked by start and end,
A tale in code, where changes blend.

Happy coding! 🌟🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 62f5e23 and 5857e71.

Files selected for processing (5)
  • server/app/query/servers.tsx (5 hunks)
  • server/app/query/view/[id]/components.tsx (2 hunks)
  • server/app/query/view/[id]/page.tsx (5 hunks)
  • sidecar/app/query/base.py (3 hunks)
  • sidecar/app/routes/websockets.py (2 hunks)
Additional comments not posted (21)
sidecar/app/routes/websockets.py (2)

37-39: Addition of start_time in NOT_FOUND response is correct.

The inclusion of start_time in the JSON response for Status.NOT_FOUND aligns with the objective of tracking start and end times.


43-47: Use of query.status_event_json for status updates is correct.

The change to use query.status_event_json for sending status updates aligns with the objective of tracking status history and ensures consistency.

server/app/query/view/[id]/components.tsx (4)

1-1: Addition of React imports is correct.

The added React imports useEffect, useState, and useRef are necessary for the updated RunTimePill component.


69-74: Update to RunTimePill props is correct.

The RunTimePill component now correctly accepts startTime and endTime as props, aligning with the objective of tracking start and end times.


80-98: useEffect logic in RunTimePill component is correct.

The useEffect logic correctly handles changes to startTime and endTime, updating the runTime state as intended.


99-99: Return statement in RunTimePill component is correct.

The return statement correctly displays the runTimeStr based on the updated state.

sidecar/app/query/base.py (6)

26-27: Addition of StatusChangeEvent named tuple is correct.

The StatusChangeEvent named tuple is correctly defined to store status and timestamp, aligning with the objective of tracking status history.


41-43: Addition of _status_history field in Query class is correct.

The _status_history field is correctly defined to store a list of StatusChangeEvent, aligning with the objective of tracking status history.


91-105: load_history_from_file method in Query class is correct.

The load_history_from_file method correctly loads status history from a file and populates _status_history as intended.


106-111: _last_status_event property in Query class is correct.

The _last_status_event property correctly returns the last status event from _status_history.


112-121: status_event_json property in Query class is correct.

The status_event_json property correctly generates a JSON representation of the last status event, including start and end times if applicable.


129-134: status setter in Query class is correct.

The status setter correctly updates _status_history and writes changes to a file, ensuring consistency with the objective of tracking status history.

server/app/query/servers.tsx (5)

62-68: Addition of StartTimeByRemoteServer and EndTimeByRemoteServer types is correct.

The StartTimeByRemoteServer and EndTimeByRemoteServer types are correctly defined to store start and end times for remote servers.


70-75: Addition of initialStartTimeByRemoteServer and initialEndTimeByRemoteServer is correct.

The initialStartTimeByRemoteServer and initialEndTimeByRemoteServer are correctly defined to initialize start and end times for remote servers.


Line range hint 191-219: Update to openStatusSocket method in RemoteServer class is correct.

The openStatusSocket method correctly handles start and end times, aligning with the objective of tracking start and end times.


203-220: updateStartTime and updateEndTime methods in RemoteServer class are correct.

The updateStartTime and updateEndTime methods correctly update the state with start and end times.


222-225: onmessage event handler in openStatusSocket method is correct.

The onmessage event handler correctly updates start and end times based on the event data.

server/app/query/view/[id]/page.tsx (4)

19-24: LGTM! Import statements are updated correctly.

The new imports for StartTimeByRemoteServer and EndTimeByRemoteServer are necessary for handling the start and end times separately.


53-56: LGTM! State variables are updated correctly.

The new state variables startTimeByRemoteServer and endTimeByRemoteServer are essential for tracking the start and end times of remote servers.


115-116: LGTM! WebSocket handling is updated correctly.

Including setStartTimeByRemoteServer and setEndTimeByRemoteServer ensures that the start and end times are set correctly for each remote server.


Line range hint 220-242:
LGTM! RunTimePill component usage is updated correctly.

The RunTimePill component now uses startTime and endTime props, allowing it to display the runtime correctly.

setRunTime(endTime - startTime);
} else {
let newIntervalId = setInterval(() => {
setRunTime(Date.now() / 1000 - startTime);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't you end up here with startTime == null?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be covered above on line 86

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, is there a reason for checking startTime again on the line 89?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, nope! just a vestige of a refactor.

return None
return query

def load_history_from_file(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to add a comment showing an example how log file looks like, so we can compare and check that it is doing the right thing

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's also a test that does this in the next PR

)

@property
def _last_status_event(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it expected to be public with _ or @Property does not work as I think it works?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is intended to be private. @property is just a helper that makes instance.method a shorthand for instance.method().

with self.status_file_path.open("w") as f:
self.logger.debug(f"setting status: {status=}")
f.write(str(status.name))
if self.status <= Status.COMPLETE:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't see the enum definition, but does this check include failed queries as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's defined here as

class Status(IntEnum):
    UNKNOWN = auto()
    STARTING = auto()
    COMPILING = auto()
    WAITING_TO_START = auto()
    IN_PROGRESS = auto()
    COMPLETE = auto()
    KILLED = auto()
    NOT_FOUND = auto()
    CRASHED = auto()

so this prevents changing the status once it's COMPLETE or higher (including KILLED and CRASHED).

if self.status <= Status.COMPLETE:
now = time.time()
self._status_history.append(StatusChangeEvent(status=status, timestamp=now))
with self.status_file_path.open("a") as f:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be better to have a class that manages the history and flushes it to the backing storage, so Query can take itself off this unrelated to its core functionality business

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, that's exactly what #71 does 🙂

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5857e71 and b83ed19.

Files selected for processing (1)
  • server/app/query/view/[id]/components.tsx (2 hunks)
Files skipped from review due to trivial changes (1)
  • server/app/query/view/[id]/components.tsx

@eriktaubeneck eriktaubeneck merged commit 8b6b38d into main Jul 12, 2024
3 checks passed
@eriktaubeneck eriktaubeneck deleted the status-events branch July 12, 2024 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants